import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
import _applyDecoratedDescriptor from "@babel/runtime/helpers/esm/applyDecoratedDescriptor";
import _isFunction from "lodash/isFunction";

var _dec, _dec2, _class;

import React from 'react';
import { Bind } from 'lodash-decorators';
import { Tooltip } from 'antd';
import { MenuContext, openMenu, renderMenuTitle } from "./utils";
import styles from "./styles.less?modules";
var LeafMenuItem = (_dec = Bind(), _dec2 = Bind(), (_class = /*#__PURE__*/function (_React$PureComponent) {
  _inherits(LeafMenuItem, _React$PureComponent);

  var _super = _createSuper(LeafMenuItem);

  function LeafMenuItem() {
    _classCallCheck(this, LeafMenuItem);

    return _super.apply(this, arguments);
  }

  _createClass(LeafMenuItem, [{
    key: "renderLeafMenuItemTitle",
    value: function renderLeafMenuItemTitle() {
      var leafMenu = this.props.leafMenu;
      return renderMenuTitle(leafMenu);
    }
  }, {
    key: "handleLeafMenuClick",
    value: function handleLeafMenuClick(e) {
      e.preventDefault();
      e.stopPropagation();
      var _this$props = this.props,
          leafMenu = _this$props.leafMenu,
          onClick = _this$props.onClick; // TODO: 直接在 LeafMenu 处理点击事件
      // 打开菜单

      openMenu(leafMenu);

      if (_isFunction(onClick)) {
        onClick(leafMenu);
      }
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props2 = this.props,
          leafMenu = _this$props2.leafMenu,
          active = _this$props2.active;
      var classNames = [styles['leaf-menu-item'], 'cpaas-leaf-menu-item'];

      if (active) {
        classNames.push(styles['leaf-menu-item-active'], 'cpaas-leaf-menu-item-active');
      }

      return /*#__PURE__*/React.createElement(Tooltip, {
        overlayClassName: styles['menu-tooltip'],
        title: /*#__PURE__*/React.createElement(MenuContext.Consumer, null, this.renderLeafMenuItemTitle)
      }, /*#__PURE__*/React.createElement("a", {
        title: renderMenuTitle(leafMenu),
        className: classNames.join(' '),
        onClick: this.handleLeafMenuClick
      }, /*#__PURE__*/React.createElement(MenuContext.Consumer, null, this.renderLeafMenuItemTitle)));
    }
  }]);

  return LeafMenuItem;
}(React.PureComponent), (_applyDecoratedDescriptor(_class.prototype, "renderLeafMenuItemTitle", [_dec], Object.getOwnPropertyDescriptor(_class.prototype, "renderLeafMenuItemTitle"), _class.prototype), _applyDecoratedDescriptor(_class.prototype, "handleLeafMenuClick", [_dec2], Object.getOwnPropertyDescriptor(_class.prototype, "handleLeafMenuClick"), _class.prototype)), _class));
export default LeafMenuItem;